The FOR statement in VectorScript executes the same script section a specified number of times. This value is held within a control variable which is evaluated by the
FOR statement to determine whether execution of the script section should continue.
The initial and final values, or limit values, of the control variable are set in the
FOR statement. These values may be
INTEGER,
LONGINT, or
CHAR values, and can be either constants or values derived from an expression. The value of the control variable is modified and evaluated by the
FOR statement prior to each pass through the script section controlled by the statement.
FOR statements come in two varieties: the
FOR-TO statement, and the
FOR-DOWNTO statement. In the
FOR-TO statement, the value of the control variable is incremented (increased) by one on each pass through the section controlled by the statement. For example:
In the FOR-TO statement, the control variable
i will be incremented by one and evaluated on each pass before the
Message() function call is executed.
In a FOR-DOWNTO statement, the value of the control variable is decremented (decreased) by a value of one on each pass until the limit value is reached. For example:
In the FOR statement, the value of
i is decremented on each pass until it reaches the limit value of one. Also note that a compound statement can be used to execute any number of other statements within the
FOR statement structure.